﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace POSGui.Classes.BusinessLogic
{
    public class ItemManager
    {
        #region Singleton
        private static ItemManager _instance;

        private ItemManager()
        {
        }

        public static ItemManager GetInstance()
        {
            if (_instance == null)
            {
                _instance = new ItemManager();
            }
            return _instance;
        }
        #endregion

        #region Public Methods

        /// <summary>
        /// Extrae la lista de items
        /// </summary>
        /// <returns></returns>
        public ERPSIA.Item[] GetItems()
        {
            ERPSIA.Item[] itemsList = null;

            WebServiceAgent webServiceConnection = new WebServiceAgent();
            itemsList = webServiceConnection.GetItems();
            return itemsList;
        }

        public static ERPSIA.ItemStoreRoomInfo GetStoreInfo(ERPSIA.Item item, ERPSIA.StoreRoom store)
        {
            foreach (ERPSIA.ItemStoreRoomInfo storeInfo in item.StoreInfo)
                if (storeInfo.StoreRoom.Id == store.Id)
                    return storeInfo;
            return null;
        }

        public static ERPSIA.StoreRoom GetStore(int storeId, ERPSIA.StoreRoom[] stores)
        {
            foreach (ERPSIA.StoreRoom store in stores)
                if (store.Id == storeId)
                    return store;
            return null;
        }

        public static ERPSIA.Item GetItem(int itemId, ERPSIA.Item[] items)
        {
            foreach (ERPSIA.Item item in items)
                if (item.Id == itemId)
                    return item;
            return null;
        }

        #endregion
    }
}